#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 3;
const int MOD = 1e9 + 7;

ll n = N, k;
ll a[N][N], b[N][N];
void matmul(ll a[N][N], ll b[N][N], ll c[N][N]) {
  ll t[N][N] = {0};
  rep(i, 0, n - 1) rep(j, 0, n - 1) {
    rep(k, 0, n - 1) t[i][j] += a[i][k] * b[k][j] % MOD;
    t[i][j] %= MOD;
  }
  rep(i, 0, n - 1) rep(j, 0, n - 1) c[i][j] = t[i][j];
}
void fastpow(ll b[N][N], ll p, ll res[N][N]) {
  rep(i, 0, n - 1) rep(j, 0, n - 1) res[i][j] = i == j;
  while (p) {
    if (p & 1) matmul(res, b, res);
    matmul(b, b, b);
    p >>= 1;
  }
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    cin >> k;
    if (k <= 3) {
      cout << 1 << endl;
      continue;
    }
    b[0][0] = 0, b[0][1] = 1, b[0][2] = 0;
    b[1][0] = 0, b[1][1] = 0, b[1][2] = 1;
    b[2][0] = 1, b[2][1] = 0, b[2][2] = 1;
    fastpow(b, k - 3, a);
    ll res = (a[2][0] + a[2][1] + a[2][2]) % MOD;
    cout << res << endl;
  }
  return 0;
}